package com.hhxy.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.hhxy.constants.SystemConstants;
import com.hhxy.handler.exception.CustomException;
import com.hhxy.model.dto.AddCommentDto;
import com.hhxy.service.CommentService;
import com.hhxy.utils.response.AppHttpCodeEnum;
import com.hhxy.utils.response.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * @author ghp
 * @date 2023/4/26
 * @title
 * @description
 */
@Api(tags = {"前台接口", "评论管理"})
@ApiSupport(author = "ghp", order = 1)
@RestController
@RequestMapping("/comment")
public class FeComment {

    @Resource
    private CommentService commentService;

    @GetMapping("/commentList")
    @ApiOperation(value = "分页条件查询文章评论")
    @ApiOperationSupport(author = "ghp", order = 1)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "当前页码", dataTypeClass = Integer.class, required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页大小", dataTypeClass = Integer.class, required = true),
            @ApiImplicitParam(name = "articleId", value = "文章id", dataTypeClass = Long.class),
    })
    public ResponseResult commentList(Integer pageNum, Integer pageSize, Long articleId) {
        // TODO 参数校验
        return commentService.commentList(pageNum, pageSize, SystemConstants.COMMENT_TYPE_ARTICLE, articleId);
    }

    @GetMapping("/linkCommentList")
    @ApiOperation(value = "分页查询友链评论", notes = "获取一页友链评论")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页号"),
            @ApiImplicitParam(name = "pageSize", value = "每页大小")
    })
    public ResponseResult linkCommentList(Integer pageNum, Integer pageSize) {
        // TODO 参数校验
        return commentService.commentList( pageNum, pageSize, SystemConstants.COMMENT_TYPE_LINK, null);
    }

    @PostMapping
    @ApiOperation(value = "添加评论")
    @ApiOperationSupport(author = "ghp", order = 1)
    public ResponseResult addComment(@RequestBody AddCommentDto addCommentDto) {
        if (Objects.isNull(addCommentDto)) {
            throw new CustomException(AppHttpCodeEnum.CLIENT_COMMENT_ERROR);
        }
        return commentService.addComment(addCommentDto);
    }



}
